import store from "/@/store";

export default {
    namespaced: true,
    state: {
      goodsData: [],
      weiboData: [],
      pageInfo: {
        size: 10,
        total: 0,
        page: 1
      }
    },
    mutations: {
      /**
       * 设置图片
       * @param {[type]} state [description]
       * @param {[type]} data  [description]
       */
      setGoodsData(state, data) {
        state.goodsData = data;
      },
      setWeiboData(state, data) {
        state.weiboData = data;
      },
      /**
       * 设置分页
       * @param {[type]} state [description]
       * @param {[type]} data  [description]
       */
      setPageInfo(state, data) {
        state.pageInfo = data;
      }
    },
    actions: {
      /**
       * 登录
       * @param  {[type]} options.commit   [description]
       * @param  {[type]} options.userName [description]
       * @param  {[type]} options.password [description]
       * @return {[type]}                  [description]
       */
      handleGoods({ commit}, params) {
        return new Promise((resolve, reject) => {
          console.log('this.$service',store);
          store.service.goods.info.page(params).then(data => {
            console.log(data,12);
            let {page,size,total}= data.pagination
            commit('setPageInfo', { size, total, page });
            commit('setGoodsData', data.list);
            resolve(data.list);
          }).catch(error => {
              console.error("错误提示", error)
              reject();
          })
        
        });
      },
      handleWeibo({ commit}, params) {
        return new Promise((resolve, reject) => {
          console.log('this.$service',store);
          store.service.weibo.weibo.page(params).then(data => {
            let {page,size,total}= data.pagination
            commit('setPageInfo', { size, total, page });
            commit('setWeiboData', data.list);
            resolve(data.list);
          }).catch(error => {
              console.error("错误提示", error)
              reject();
          })
        
        });
      },
      /**
       * [handleGoods description]
       * @param  {[type]} options.commit [description]
       * @return {[type]}                [description]
       */
      handleSearch({ commit }) {
        return new Promise((resolve, reject) => {});
      }
    }
  };
  